package com.example.service.impl;

import com.example.mapper.RecordMapper;
import com.example.pojo.PageBean;
import com.example.pojo.Record;
import com.example.service.RecordService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;
import java.util.Map;

@Service
public class RecordServiceImpl implements RecordService {

    @Autowired
    private RecordMapper recordMapper;

    @Override
    public PageBean<Record> list(Integer pageNum, Integer pageSize, String sellerName, String customerName, String goodsName, Integer cateId) {
        // 1. 开启分页
        PageHelper.startPage(pageNum, pageSize);

        // 2. 执行查询
        List<Record> records = recordMapper.list(sellerName, customerName, goodsName, cateId);
        Page<Record> page = (Page<Record>) records;

        // 3. 封装分页结果
        return new PageBean<>(page.getTotal(), page.getResult());
    }

    @Override
    public Record findById(Integer id) {
        return recordMapper.findById(id);
    }

    @Override
    public List<Map<String, Object>> statistics(LocalDateTime startTime, LocalDateTime endTime) {
        return recordMapper.statistics(startTime, endTime);
    }
}